﻿using Iservices;
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Model;
using EFEntity;
using System.Linq;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AutoMapper;

namespace Services
{
    /// <summary>
    ///  公共字段设置，包括薪酬设置，职称设置，国籍，民族，宗教信仰，政治面貌，教育年限，学历,专业，特长，爱好，培训项目，培训成绩，奖励项目，奖励等级
    /// </summary>
    public class config_public_charServices:Iconfig_public_charServices
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;

        public config_public_charServices(MyDbContext myDbContext, IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        public async Task<List<config_public_char>> Select()
        {
            List<Econfig_public_char> list = new List<Econfig_public_char>();
            await Task.Run(() => {
                list = myDbContext.config_public_char.ToList();
            });
            List<config_public_char> list2 = mapper.Map<List<config_public_char>>(list);
            return list2;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public async Task<int> Update(config_public_char b)
        {
            Econfig_public_char etest = mapper.Map<Econfig_public_char>(b);
            myDbContext.Attach(etest);
            myDbContext.Entry<Econfig_public_char>(etest).State = EntityState.Modified;
            return await myDbContext.SaveChangesAsync();
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public async Task<int> Add(config_public_char b)
        {
            Econfig_public_char etest = mapper.Map<Econfig_public_char>(b);
            myDbContext.config_public_char.Add(etest);
            int result = await myDbContext.SaveChangesAsync();
            return result;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public async Task<int> Del(int p)
        {
            Econfig_public_char st = myDbContext.config_public_char.Find(p);
            myDbContext.config_public_char.Remove(st);
            int result = await myDbContext.SaveChangesAsync();
            return result;
        }
     
    }
}

